<?php

/**
 * This Validator checks if an user with the given name is already registered in the database 
 * @author Clueth
 *
 */

class Somi_Validate_ExistEmail extends Zend_Validate_Abstract {

	const NOT_MATCH = 'EmailAssigned';
	 
	protected $_messageTemplates = array(
	self::NOT_MATCH => 'Die angegebene Emailadresse ist unserer Datenbank nicht bekannt. Bitte versuchen Sie es noch einmal.'
	);


	public function isValid($email) {

		 
		$email = (string) $email;
		 
		$error = false;
		 
		if(!$this->checkUnique($email)){
			$error = true;
			$this->_error(self::NOT_MATCH);
			 
		}
		else
			return !$error;
	}

	private function checkUnique($email){

		$firma = new Somi_Models_Firma();
		$select = $firma->select()->from('firma')->where('email=?',$email);
		$result = $firma->getAdapter()->fetchOne($select);

		if($result){
			return true;
		}
		return false;
	}
	 
}

?>